import preutils from '@/common/preutils.js'
import check from '@/common/check.js'
export default {

	printData: function(outputStream, e) {
		var that = this;
		var text = "";
		var count = 0;
		for (var i = 0; i < e.goods.length; i++) {
			var item = e.goods[i];
			this.printTitle(outputStream, e, item);
		}
	},
	getToCity(info) {
		var memberInfo = uni.getStorageSync(preutils.userinfo);
		let city = check.strNullReplace(info.to_city, '');
		let county = check.strNullReplace(info.to_county, '');
		var address = memberInfo.site_name + ' -- ' + city + '' + county;
		return address;
	},
	getDeliveryType(info) {
		return info.delivery_type == 2 ? '送货' : '自提';
	},

	getOrderAmount(info) {
		var order_amount_pay = ''
		switch (info.order_amount_pay) {
			case 10: {
				order_amount_pay = '现付'
				break
			}
			case 20: {
				order_amount_pay = '提付'
				break
			}
			case 30: {
				order_amount_pay = '回单付'
				break
			}
			case 40: {
				order_amount_pay = '月结'
				break
			}
			case 50: {
				order_amount_pay = '扣付'
				break
			}
		}
		return info.order_amount + '/' + order_amount_pay;
	},

	printSendName(info) {
		return info.send_username + '/' + info.send_mobile;
	},
	printTakeName(info) {
		return info.take_username + '/' + info.take_mobile;
	},
	printReceipt(info) {
		var title = '';
		if (info.is_receipt == '2') {
			if (Number(info.receipt_num) > 0) {
				title = info.receipt_num + '份/' + this.receiptTypeMap[info.receipt_type];
			} else {
				title = this.receiptTypeMap[info.receipt_type];
			}
		}
		return title;
	},
	getReceiptTypeName(e) {
		var name = '';
		switch (e) {
			case 0: {
				name = '无';
				break
			}
			case 1: {
				name = '托运单签名盖章返回';
				break
			}
			case 2: {
				name = '送货单签名盖章返回';
				break
			}
			case 3: {
				name = '回单签名盖章返回';
				break
			}
			case 4: {
				name = '其他';
				break
			}
			case 5: {
				name = '收条';
				break
			}
		}
		return name;
	},
	printGoodsName(info) {
		var names = [];
		if (info.goods != undefined) {
			for (let i = 0; i < info.goods.length; i++) {
				names.push(info.goods[i]['goods_name']);
			}
			return names.join("/");;
		}
		return names.join("/");;
	},
	printGoodsNum(info) {
		var nums = [];
		if (info.goods != undefined) {
			for (let i = 0; i < info.goods.length; i++) {
				nums.push(info.goods[i]['goods_nums']);
			}
			return nums.join("/");
		}
		return nums.join("/");;
	},
	printGoodsPack(info) {
		var packs = [];
		if (info.goods != undefined) {
			for (let i = 0; i < info.goods.length; i++) {
				packs.push(info.goods[i]['goods_pack']);
			}
			return packs.join("/");;
		}
		return packs.join("/");;
	},
	printGoodsWeight(info) {
		var packs = [];
		if (info.goods != undefined) {
			for (let i = 0; i < info.goods.length; i++) {
				packs.push(info.goods[i]['total_weight']);
			}
			return packs.join("/");;
		}
		return packs.join("/");;
	},
	printGoodsVolume(info) {
		var packs = [];
		if (info.goods != undefined) {
			for (let i = 0; i < info.goods.length; i++) {
				packs.push(info.goods[i]['total_volume']);
			}
			return packs.join("/");;
		}
		return packs.join("/");;
	},

	printNewDate() {
		return this.parseTime(new Date());
	},
	
	// 日期格式化
	parseTime(time, pattern) {
		if (arguments.length === 0 || !time) {
			return null
		}
		const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
		let date
		if (typeof time === 'object') {
			date = time
		} else {
			if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
				time = parseInt(time)
			} else if (typeof time === 'string') {
				time = time.replace(new RegExp(/-/gm), '/');
			}
			if ((typeof time === 'number') && (time.toString().length === 10)) {
				time = time * 1000
			}
			date = new Date(time)
		}
		const formatObj = {
			y: date.getFullYear(),
			m: date.getMonth() + 1,
			d: date.getDate(),
			h: date.getHours(),
			i: date.getMinutes(),
			s: date.getSeconds(),
			a: date.getDay()
		}
		const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
			let value = formatObj[key]
			// Note: getDay() returns 0 on Sunday
			if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
			if (result.length > 0 && value < 10) {
				value = '0' + value
			}
			return value || 0
		})
		return time_str
	}

}